Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: [],
    hotList: [],
    list: [],
    num: {},
    query: {
      page: 1,
      limit: 10
    },
    nothing: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    // 轮播图
    const res = await wx.http.get('/index/index')
    this.setData({ banner: res.data.banner })
    // 热门推荐
    const hot = await wx.http.get('/index/hot')
    this.setData({ hotList: hot.data.list })
    this.init()
  },

  async init() {
    // 最近更新
    const res = await wx.http.get('/index/new', {
      ...this.data.query
    })
    console.log(this.data.list, res.data.list)
    this.setData({
      list: [...this.data.list, ...res.data.list.data],
      num: {
        num_day: res.data.num_day,
        num_week: res.data.num_week
      }
    })
    if (res.data.list.data < this.data.query.limit) {
      this.onReachBottom = function () { }
      this.setData({ nothing: true })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    // this.getTabBar获取自定义tabBar组件实例，设置对应显示高亮
    this.getTabBar().setData({ selected: 0 })
    this.onReachBottom = function () {
      console.log('bottom')
      this.data.query.page++
      this.init()
    }
  },
  onReachBottom() {
    console.log('bottom')
    this.data.query.page++
    this.init()
  }

})